package com.dd.service;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import com.dd.dao.DdKeywordDAO;
import com.dd.dao.DdNodeDAO;
import com.dd.dao.DdOrderDAO;
import com.dd.dao.DdShopDAO;
import com.dd.dao.DdShopgoodsDAO;
import com.dd.dao.DdSystemuserDAO;
import com.dd.dao.DdUserDAO;
import com.dd.dao.DictDAO;
import com.dd.entity.*;
import com.dd.util.DateStrFormat;
import com.dd.util.PageList;
import com.dd.util.PubFun;

public class ShopService {

	private DdUserDAO ddUserDAO;
	private DdShopDAO ddShopDAO;
	private DdShopgoodsDAO ddGoodDAO;
	private DictDAO dictDAO;
	private DdNodeDAO ddNodeDAO;
	private DdKeywordDAO ddKeywordDAO;
	private DdSystemuserDAO ddSystemuserDAO;

	public static boolean isNum(String str) {
		for (int i = str.length(); --i >= 0;) {
			if (!Character.isDigit(str.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	public String clearStr(String str) {
		try {
			str = str.replace("\"", "'").replace("\r\n", "").replace("\r", "")
					.replace("\n", "");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return str;
	}

	public void setDdKeywordDAO(DdKeywordDAO ddKeywordDAO) {
		this.ddKeywordDAO = ddKeywordDAO;
	}

	private String getStyleValue(int styleType, long styleValue, DictDAO ddao) {

		// int src = Integer.parseInt(purpose);
		boolean b = true;
		int count = 0;
		Dict rootd = ddao.findById(styleType);
		String str = rootd.getNodeValue();
		while (b) {
			long tmp = styleValue % 2;
			// public Dict findByTypeAndCode(int nodeType,int root,long code) {
			if (tmp == 1) {
				Dict dict = ddao.findByTypeAndCode(2, styleType, (long) Math
						.pow(2, count));
				str = str + "," + dict.getNodeValue();
				styleValue = styleValue * (long) Math.pow(2, count)
						- (long) Math.pow(2, count);
				count = -1;
			} else {
				styleValue = styleValue / 2;
			}
			count++;
			if (styleValue == 1) {
				Dict dict = ddao.findByTypeAndCode(2, styleType, (long) Math
						.pow(2, count));
				str = str + "," + dict.getNodeValue();
				b = false;
			}
			if (styleValue == 0) {
				b = false;
			}
		}
		return str;
	}

	/**
	 * 
	 * @param styleType
	 *            上级ID
	 * @param styleValue
	 *            CODE的值
	 * @param ddao
	 * @return
	 */
	public String getStyleValue2(int styleType, long styleValue, DictDAO ddao) {

		// int src = Integer.parseInt(purpose);
		boolean b = true;
		int count = 0;
		Dict rootd = ddao.findById(styleType);
		String str = "";
		while (b) {
			long tmp = styleValue % 2;
			// public Dict findByTypeAndCode(int nodeType,int root,long code) {
			if (tmp == 1) {
				Dict dict = ddao.findByTypeAndCode(2, styleType, (long) Math
						.pow(2, count));
				if (dict != null) {
					str = str + "," + dict.getNodeCode();
				}
				styleValue = styleValue * (long) Math.pow(2, count)
						- (long) Math.pow(2, count);
				count = -1;
			} else {
				styleValue = styleValue / 2;
			}
			count++;
			if (styleValue == 1) {
				Dict dict = ddao.findByTypeAndCode(2, styleType, (long) Math
						.pow(2, count));
				str = str + "," + dict.getNodeCode();
				b = false;
			}
			if (styleValue == 0) {
				b = false;
			}
		}
		return str;
	}

	/**
	 * 
	 * @param styleType
	 *            上级ID
	 * @param styleValue
	 *            CODE的值
	 * @param ddao
	 * @return
	 */
	public String getStyleValue3(int styleType, long styleValue, DictDAO ddao) {

		// int src = Integer.parseInt(purpose);
		boolean b = true;
		int count = 0;
		Dict rootd = ddao.findById(styleType);
		String str = "";
		while (b) {
			long tmp = styleValue % 2;
			// public Dict findByTypeAndCode(int nodeType,int root,long code) {
			if (tmp == 1) {
				Dict dict = ddao.findByTypeAndCode(14, styleType, (long) Math
						.pow(2, count));
				if (dict != null) {
					str = str + "," + dict.getNodeCode();
					styleValue = styleValue * (long) Math.pow(2, count)
							- (long) Math.pow(2, count);
				}
				count = -1;
			} else {
				styleValue = styleValue / 2;
			}
			count++;
			if (styleValue == 1) {
				Dict dict = ddao.findByTypeAndCode(14, styleType, (long) Math
						.pow(2, count));
				if (dict != null) {
					str = str + "," + dict.getNodeCode();
				}
				b = false;
			}
			if (styleValue == 0) {
				b = false;
			}
		}
		return str;
	}

	// 根据类位或算法反算出代码中含有那些CODE或者VALUE
	public String getNodeValue(int src, int nodetype, DictDAO ddao,
			boolean isCode) {
		String str = "";
		try {
			// int src = Integer.parseInt(purpose);
			boolean b = true;
			int count = 0;
			while (b) {
				int tmp = src % 2;
				if (tmp == 1) {
					Dict dict = ddao.findByTypeAndCode(nodetype, (int) Math
							.pow(2, count));
					if (str.equals("")) {
						str = (isCode == true ? (dict.getNodeCode() + "")
								: dict.getNodeValue());
					} else {
						str = str
								+ ","
								+ (isCode == true ? dict.getNodeCode() : dict
										.getNodeValue());
					}
					src = src * (int) Math.pow(2, count)
							- (int) Math.pow(2, count);
					count = -1;
				} else {
					src = src / 2;
				}
				count++;
				if (src == 1) {
					Dict dict = ddao.findByTypeAndCode(nodetype, (int) Math
							.pow(2, count));
					if (dict != null) {
						if (str.equals("")) {
							str = (isCode == true ? (dict.getNodeCode() + "")
									: dict.getNodeValue());
						} else {
							str = str
									+ ","
									+ (isCode == true ? dict.getNodeCode()
											: dict.getNodeValue());
						}
					}
					b = false;
				}
				if (src == 0) {
					b = false;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return str;
	}

	private String getNodeValue1(int src, int nodetype, DictDAO ddao,
			boolean isCode) {
		String str = "";
		// int src = Integer.parseInt(purpose);
		boolean b = true;
		int count = 0;
		while (b) {
			int tmp = src % 2;
			if (tmp == 1) {
				Dict dict = ddao.findByTypeAndCode(nodetype, (int) Math.pow(2,
						count));
				if (str.equals("")) {
					str = (isCode == true ? (dict.getNodeCode() + "") : dict
							.getNodeValue());
				} else {
					str = str
							+ ","
							+ (isCode == true ? dict.getNodeCode() : dict
									.getNodeValue());
				}
				src = src * (int) Math.pow(2, count) - (int) Math.pow(2, count);
				count = -1;
			} else {
				src = src / 2;
			}
			count++;
			if (src == 1) {
				Dict dict = ddao.findByTypeAndCode(nodetype, (int) Math.pow(2,
						count));
				if (str.equals("")) {
					str = (isCode == true ? (dict.getNodeCode() + "") : dict
							.getNodeValue());
				} else {
					str = str
							+ ","
							+ (isCode == true ? dict.getNodeCode() : dict
									.getNodeValue());
				}
				b = false;
			}
			if (src == 0) {
				b = false;
			}
		}
		return str;
	}

	public DdNodeDAO getDdNodeDAO() {
		return ddNodeDAO;
	}

	public void setDdNodeDAO(DdNodeDAO ddNodeDAO) {
		this.ddNodeDAO = ddNodeDAO;
	}

	public DictDAO getDictDAO() {
		return dictDAO;
	}

	public void setDictDAO(DictDAO dictDAO) {
		this.dictDAO = dictDAO;
	}

	public DdUserDAO getDdUserDAO() {
		return ddUserDAO;
	}

	public void setDdUserDAO(DdUserDAO ddUserDAO) {
		this.ddUserDAO = ddUserDAO;
	}

	public DdShopDAO getDdShopDAO() {
		return ddShopDAO;
	}

	public DdKeywordDAO getDdKeywordDAO() {
		return ddKeywordDAO;
	}

	public void setDdShopDAO(DdShopDAO ddShopDAO) {
		this.ddShopDAO = ddShopDAO;
	}

	public DdShopgoodsDAO getDdGoodDAO() {
		return ddGoodDAO;
	}

	public void setDdGoodDAO(DdShopgoodsDAO ddGoodDAO) {
		this.ddGoodDAO = ddGoodDAO;
	}

	private boolean checkDiscount(DdShop ds) {
		if (ds.getDiscountbeg() == null || ds.getDiscountend() == null) {
			return false;
		}
		Date now = new Date();
		if (now.getTime() < ds.getDiscountend().getTime()) {
			return true;
		}
		return false;

	}

	// 获取价格
	public float getPrice(DdShop ds, String date, String ltype, int num) {
		try {
			if (ds.getType().intValue() == 2) {
				return ds.getBookprice();
			}
			int ordnum = 1;
			if (ds.getBooktype().intValue() == 1) {
				ordnum = num;
			}
			if (ds.getDiscountbeg() == null || ds.getDiscountend() == null) {
				if (ltype.equals("1")) {
					return ds.getBookprice() * ordnum;
				} else {
					return ds.getBookprice2() * ordnum;
				}

			}
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date s_date = (Date) sdf.parse(date);
			if (s_date.getTime() > ds.getDiscountbeg().getTime()
					&& s_date.getTime() < ds.getDiscountend().getTime()) {
				if (ltype.equals("1")) {
					return ds.getDiscountprice() * ordnum;
				} else {
					return ds.getDiscountprice2() * ordnum;
				}

			}
			if (ltype.equals("1")) {
				return ds.getBookprice() * ordnum;
			} else {
				return ds.getBookprice2() * ordnum;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ds.getBookprice();
		}
	}

	// 获取运动场馆价格
	public float getPrice1(DdShop ds, String date, int from, int to) {
		try {
			boolean isZero = false;
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date s_date = (Date) sdf.parse(date);
			int day = s_date.getDay();// 获取星期几 0-星期日.1-6=星期1-6
			List list = this.getDdGoodDAO().findByShopidAndDay(ds.getId(), day);
			DdShopgoods dsd1 = (DdShopgoods) list.get(0);
			DdShopgoods dsd2 = (DdShopgoods) list.get(1);
			float price = 0F;
			for (int i = from; i < to; i++) {
				if (i < ds.getStyleType().intValue()) {// 早上价格
					if (dsd1.getPrice() < 1) {
						isZero = true;
					}
					price = price + dsd1.getPrice();
				} else {// 晚上价格
					if (dsd2.getPrice() < 1) {
						isZero = true;
					}
					price = price + dsd2.getPrice();
				}
			}
			if (isZero) {
				price = 0;
			}
			return price;
		} catch (Exception e) {
			e.printStackTrace();
			return 0F;
		}
	}

	// 获取礼品价格
	public float getPrice2(DdShop ds, DdShopgoods dsg, String date) {
		try {
			if (ds.getDiscountbeg() == null || ds.getDiscountend() == null) {// 无活动返回现价
				return dsg.getDiscount();
			}
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date s_date = (Date) sdf.parse(date);
			// 送货日期在区间之内
			if (s_date.getTime() > ds.getDiscountbeg().getTime()
					&& s_date.getTime() < ds.getDiscountend().getTime()) {

				return dsg.getPrice2();
			} else {
				return dsg.getDiscount();
			}

		} catch (Exception e) {
			e.printStackTrace();
			return 0F;
		}
	}

	public String getPriceDes2(DdShop ds, DdShopgoods dsg, String date) {
		try {
			if (ds.getDiscountbeg() == null || ds.getDiscountend() == null) {// 无活动返回现价
				return "";
			}
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date s_date = (Date) sdf.parse(date);
			// 送货日期在区间之内
			if (s_date.getTime() > ds.getDiscountbeg().getTime()
					&& s_date.getTime() < ds.getDiscountend().getTime()) {

				return ds.getDiscountremark();
			} else {
				return "";
			}

		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}

	// 获取价格备注
	public String getPriceDes(DdShop ds, String date, String ltype) {
		try {
			if (ds.getType().intValue() == 2) {
				return ds.getBookpricedes();
			}
			if (ds.getDiscountbeg() == null || ds.getDiscountend() == null) {
				if (ltype.equals("1")) {
					return ds.getBookpricedes();
				} else {
					return ds.getBookprice2des();
				}

			}
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date s_date = (Date) sdf.parse(date);
			if (s_date.getTime() > ds.getDiscountbeg().getTime()
					&& s_date.getTime() < ds.getDiscountend().getTime()) {
				if (ltype.equals("1")) {
					return ds.getDiscountpricedes();
				} else {
					return ds.getDiscountprice2des();
				}

			}
			if (ltype.equals("1")) {
				return ds.getBookpricedes();
			} else {
				return ds.getBookprice2des();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}

	// 新商家简要
	public void info2(HttpServletRequest request, DdShop ds, StringBuffer sbf) {
		String url = PubFun.getStringPinYin(ds.getName()).substring(0, 3);
		if (ds.getUrl() != null && ds.getUrl().length() > 2) {
			url = ds.getUrl();
		}
		sbf.append("{");
		sbf.append("\"name\":\"" + clearStr(ds.getName()) + "\"");
		sbf.append(",\"issend\":\"" + ds.getIssend() + "\"");
		sbf.append(",\"isbooking\":\"" + ds.getIsbooking() + "\"");
		sbf.append(",\"iscoupon\":\"" + ds.getIscoupon() + "\"");
		sbf.append(",\"phone\":\"" + clearStr(ds.getPhone()) + "\"");
		sbf.append(",\"shophours\":\"" + clearStr(ds.getShophours()) + "\"");
		String cost = "0-50";
		if (ds.getCost() != null && ds.getCost().intValue() == 2) {
			cost = "50-100";
		} else if (ds.getCost() != null && ds.getCost().intValue() == 3) {
			cost = "100-200";
		} else if (ds.getCost() != null && ds.getCost().intValue() == 4) {
			cost = "200以上";
		}
		String shopstyle = "其他";
		// "请直接填入:1,2,3,4 ……
		// 1.私房菜 2.自助餐 3.川湘菜 4.粤菜 5.闽菜 6.西餐7.日本料理 8.泰国菜 9.韩国料理 10.越南菜 11.快餐 "
		if (ds.getShopstyle() != null && ds.getShopstyle().intValue() == 1) {
			shopstyle = "私房菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 2) {
			shopstyle = "自助餐";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 3) {
			shopstyle = "川湘菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 4) {
			shopstyle = "粤菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 5) {
			shopstyle = "闽菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 6) {
			shopstyle = "西餐";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 7) {
			shopstyle = "日本料理";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 8) {
			shopstyle = "泰国菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 9) {
			shopstyle = "韩国料理";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 10) {
			shopstyle = "越南菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 11) {
			shopstyle = "外卖,送餐";
		}
		sbf.append(",\"cost\":\"" + cost + "\"");
		sbf.append(",\"shopstyle\":\"" + ds.getStylevalue() + "\"");
		sbf.append(",\"wifi\":\"" + ds.getWifi() + "\"");
		sbf.append(",\"visa\":\"" + ds.getVisa() + "\"");
		sbf.append(",\"park\":\"" + ds.getPark() + "\"");
		sbf.append(",\"sendtype\":\"" + (ds.getSendtype() == 1 ? "外送" : "自取")
				+ "\"");
		sbf.append(",\"sendtime\":\"" + clearStr(ds.getSendtime()) + "\"");
		sbf.append(",\"sendrange\":\"" + clearStr(ds.getSendrange()) + "\"");
		sbf.append(",\"sendreq\":\"" + clearStr(ds.getSendreq()) + "\"");
		sbf.append(",\"sendfee\":\"" + clearStr(ds.getSendfee()) + "\"");
		sbf.append(",\"sendpaymethod\":\""
				+ (ds.getSendpaymethod() == 1 ? "到付" : "在线付款") + "\"");
		sbf.append(",\"senddiscount\":\"" + clearStr(ds.getSenddiscount())
				+ "\"");
		sbf.append(",\"bookprice\":\"" + ds.getBookprice() + "\"");
		sbf.append(",\"bookpriceuse\":\"" + clearStr(ds.getBookpriceuse())
				+ "\"");
		sbf.append(",\"bookreq\":\"" + clearStr(ds.getBookreq()) + "\"");
		String discount = "无";
		if (ds.getDiscount() > 0F && ds.getDiscount() < 10F) {
			discount = ds.getDiscount() + "折";
		}
		sbf.append(",\"discount\":\"" + discount + "\"");
		sbf.append(",\"url\":\"" + url + "\"");
		sbf.append(",\"coupon3\":\"" + clearStr(ds.getCoupon3()) + "\"");
		sbf.append("}");

	}

	// 新商家详情
	public void info(HttpServletRequest request, DdShop ds, StringBuffer sbf) {

		sbf.append("{");
		sbf.append("\"name\":\"" + clearStr(ds.getName()) + "\"");
		sbf.append(",\"bankacc\":\"" + ds.getBankacc() + "\"");
		sbf.append(",\"bankaccname\":\"" + ds.getBankaccname() + "\"");
		sbf.append(",\"address\":\"" + clearStr(ds.getAddress()) + "\"");
		sbf.append(",\"posx\":\"" + clearStr(ds.getPosx()) + "\"");
		sbf.append(",\"posy\":\"" + clearStr(ds.getPosy()) + "\"");
		sbf.append(",\"phone\":\"" + clearStr(ds.getPhone()) + "\"");
		sbf.append(",\"mobile\":\"" + clearStr(ds.getMobile()) + "\"");
		sbf.append(",\"bossphone\":\"" + clearStr(ds.getBossphone()) + "\"");
		sbf.append(",\"landmark\":\"" + clearStr(ds.getLandmark()) + "\"");
		sbf.append(",\"shophours\":\"" + clearStr(ds.getShophours()) + "\"");
		String cost = "0-50";
		if (ds.getCost() != null && ds.getCost().intValue() == 2) {
			cost = "50-100";
		} else if (ds.getCost() != null && ds.getCost().intValue() == 3) {
			cost = "100-200";
		} else if (ds.getCost() != null && ds.getCost().intValue() == 4) {
			cost = "200以上";
		}
		String shopstyle = "其他";
		// "请直接填入:1,2,3,4 ……
		// 1.私房菜 2.自助餐 3.川湘菜 4.粤菜 5.闽菜 6.西餐7.日本料理 8.泰国菜 9.韩国料理 10.越南菜 11.快餐 "
		if (ds.getShopstyle() != null && ds.getShopstyle().intValue() == 1) {
			shopstyle = "私房菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 2) {
			shopstyle = "自助餐";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 3) {
			shopstyle = "川湘菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 4) {
			shopstyle = "粤菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 5) {
			shopstyle = "闽菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 6) {
			shopstyle = "西餐";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 7) {
			shopstyle = "日本料理";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 8) {
			shopstyle = "泰国菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 9) {
			shopstyle = "韩国料理";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 10) {
			shopstyle = "越南菜";
		} else if (ds.getShopstyle() != null
				&& ds.getShopstyle().intValue() == 11) {
			shopstyle = "外卖";
		}
		sbf.append(",\"cost\":\"" + cost + "\"");
		sbf.append(",\"shopstyle\":\"" + shopstyle + "\"");
		sbf.append(",\"wifi\":\"" + (ds.getWifi() == 0 ? "无" : "有") + "\"");
		sbf.append(",\"visa\":\"" + (ds.getVisa() == 0 ? "无" : "有") + "\"");
		String park = "无";
		if (ds.getPark().intValue() == 0) {
			park = "免费车位";
		} else if (ds.getPark().intValue() > 0) {
			park = "收费车位:" + ds.getPark() + "元";
		}
		sbf.append(",\"park\":\"" + park + "\"");
		sbf.append(",\"shoptype\":\"" + (ds.getShoptype() == 1 ? "独家" : "连锁")
				+ "\"");
		sbf.append(",\"bus\":\"" + clearStr(ds.getBus()) + "\"");
		sbf.append(",\"sendtype\":\"" + (ds.getSendtype() == 1 ? "外送" : "自取")
				+ "\"");
		sbf.append(",\"sendtime\":\"" + clearStr(ds.getSendtime()) + "\"");
		sbf.append(",\"sendrange\":\"" + clearStr(ds.getSendrange()) + "\"");
		sbf.append(",\"sendreq\":\"" + clearStr(ds.getSendreq()) + "\"");
		sbf.append(",\"sendfee\":\"" + clearStr(ds.getSendfee()) + "\"");
		sbf.append(",\"sendpaymethod\":\""
				+ (ds.getSendpaymethod() == 1 ? "到付" : "在线付款") + "\"");
		sbf.append(",\"senddiscount\":\"" + clearStr(ds.getSenddiscount())
				+ "\"");
		sbf.append(",\"loge0\":\"" + (ds.getLoge0() == 0 ? "无" : "有") + "\"");
		sbf.append(",\"loge1\":\"" + (ds.getLoge1() == 0 ? "无" : "有") + "\"");
		sbf.append(",\"bookprice\":\"" + ds.getBookprice() + "\"");
		sbf.append(",\"bookpriceuse\":\"" + clearStr(ds.getBookpriceuse())
				+ "\"");
		sbf
				.append(",\"pricedivide\":\"" + clearStr(ds.getPricedivide())
						+ "\"");
		sbf.append(",\"bookreq\":\"" + clearStr(ds.getBookreq()) + "\"");
		String discount = "";
		if (ds.getDiscount() > 0F && ds.getDiscount() < 10F) {
			discount = ds.getDiscount() + "折";
		}
		sbf.append(",\"discount\":\"" + discount + "\"");
		String menu = "[]";
		sbf.append(",\"menus\":" + menu + "");
		sbf.append("}");

	}

	// 商家详情
	public void shopInfo(HttpServletRequest request, DdShop ds, StringBuffer sbf) {

		String stylevalue = "";
		if (ds.getType().intValue() == 1) {
			stylevalue = this.getStyleValue(ds.getStyleType(), ds.getStyle(),
					this.getDictDAO());
		}
		int purposetype = 4;
		int costtype = 5;
		String discount = "0";
		String discounttext = "0";
		if (ds.getType().intValue() == 1) {
			// 餐厅 --检测有无优惠活动
			if (ds.getDiscountend() != null) {
				if (ds.getDiscountend().getTime() > (new Date().getTime())) {
					discount = DateStrFormat.getCurrentTime1(ds
							.getDiscountbeg())
							+ "到"
							+ DateStrFormat
									.getCurrentTime1(ds.getDiscountend())
							+ ds.getDiscountremark();
					discounttext = ds.getDiscounttext();
				}
			}
		} else if (ds.getType().intValue() == 2) {
			purposetype = 6;
			costtype = 7;
		} else if (ds.getType().intValue() == 3) {
			purposetype = 8;
			costtype = 7;
		} else if (ds.getType().intValue() == 4) {
			purposetype = 10;
			costtype = 11;
		} else {
			purposetype = 12;
			costtype = 11;
		}
		Dict dict = this.getDictDAO().findByTypeAndCode(costtype, ds.getCost());
		Dict areaDict = this.getDictDAO().findByTypeAndCode(1,
				Integer.parseInt(ds.getArea()));
		String discountvalue = "";
		if (ds.getDiscount() != null && ds.getDiscount() > 0
				&& ds.getDiscount() < 10) {
			discountvalue = ds.getDiscount() + "折";
		}
		sbf.append("<shop  id=\""
				+ ds.getId()
				+ "\" name=\""
				+ ds.getName()
				+ "\" shophours=\""
				+ ds.getShophours()
				+ "\" style=\""
				+ stylevalue
				+ "\" phone=\""
				+ ds.getPhone()
				+ "\"  moblie=\""
				+ ds.getMobile()
				+ "\" address=\""
				+ ds.getAddress()
				+ "\" cost=\""
				+ dict.getNodeValue()
				+ "\" area=\""
				+ areaDict.getNodeValue()
				+ "\" road=\""
				+ ds.getRoad()
				+ "\" landmark=\""
				+ ds.getLandmark()
				+ "\" range=\""
				+ ds.getRange()
				+ "\" bus=\""
				+ ds.getBus()
				+ "\" parking=\""
				+ ds.getParking()
				+ "\" purpose=\""
				+ this.getNodeValue(ds.getPurpose(), purposetype, this
						.getDictDAO(), false) + "\" service=\""
				+ ds.getService() + "\" description=\"" + ds.getDescription()
				+ "\" description2=\"" + ds.getDescription2() + "\" pic3=\""
				+ ds.getPic3() + "\" pic4=\"" + ds.getPic4() + "\" pic5=\""
				+ ds.getPic5() + "\" pic6=\"" + ds.getPic6() + "\" pic7=\""
				+ ds.getPic7() + "\" pic8=\"" + ds.getPic8() + "\" suggest=\""
				+ ds.getSuggest() + "\" discountvalue=\"" + discountvalue
				+ "\" discount=\"" + discount + "\" discounttext=\""
				+ discounttext + "\" loge=\"" + ds.getLoge() + "\" real=\""
				+ ds.getReal() + "\">");
		List goodli = this.getDdGoodDAO().findByShopid(ds.getId());
		if (goodli.size() != 0) {
			sbf.append("<goods>");
			for (int j = 0; j < goodli.size(); j++) {
				DdShopgoods dsg = (DdShopgoods) goodli.get(j);
				if (!isNum(dsg.getName())) {
					sbf.append("<good  id=\"" + dsg.getId() + "\" price=\""
							+ dsg.getPrice() + "\" type=\"" + dsg.getType()
							+ "\" pic1=\"" + dsg.getPic1() + "\" pic2=\""
							+ dsg.getPic2() + "\" pic3=\"" + dsg.getPic3()
							+ "\" name=\"" + dsg.getName() + "\" />");
				}

			}
			sbf.append("</goods>");
		}
		sbf.append("</shop></root>");

	}

	// 娱乐详情
	public void shopInfo2(HttpServletRequest request, DdShop ds,
			StringBuffer sbf) {
		Dict dict = this.getDictDAO().findByTypeAndCode(7, ds.getCost());
		sbf.append("<shop  id=\""
				+ ds.getId()
				+ "\" name=\""
				+ ds.getName()
				+ "\" shophours=\""
				+ ds.getShophours()
				+ "\" phone=\""
				+ ds.getPhone()
				+ "\"  moblie=\""
				+ ds.getMobile()
				+ "\" address=\""
				+ ds.getAddress()
				+ "\" cost=\""
				+ dict.getNodeValue()
				+ "\" area=\""
				+ ds.getArea()
				+ "\" road=\""
				+ ds.getRoad()
				+ "\" landmark=\""
				+ ds.getLandmark()
				+ "\" range=\""
				+ ds.getRange()
				+ "\" bus=\""
				+ ds.getBus()
				+ "\" parking=\""
				+ ds.getParking()
				+ "\" purpose=\""
				+ this.getNodeValue(ds.getPurpose(), 6, this.getDictDAO(),
						false) + "\" service=\"" + ds.getService()
				+ "\" description=\"" + ds.getDescription() + "\" pic3=\""
				+ ds.getPic3() + "\" pic4=\"" + ds.getPic4() + "\" pic5=\""
				+ ds.getPic5() + "\" pic6=\"" + ds.getPic6() + "\" pic7=\""
				+ ds.getPic7() + "\" pic8=\"" + ds.getPic8() + "\" >");
		sbf.append("</shop></root>");
	}

	// 酒店
	public void shopInfo3(HttpServletRequest request, DdShop ds,
			StringBuffer sbf) {
		Dict dict = this.getDictDAO().findByTypeAndCode(7, ds.getCost());
		sbf.append("<shop  id=\""
				+ ds.getId()
				+ "\" name=\""
				+ ds.getName()
				+ "\" shophours=\""
				+ ds.getShophours()
				+ "\" phone=\""
				+ ds.getPhone()
				+ "\"  moblie=\""
				+ ds.getMobile()
				+ "\" address=\""
				+ ds.getAddress()
				+ "\" cost=\""
				+ dict.getNodeValue()
				+ "\" area=\""
				+ ds.getArea()
				+ "\" road=\""
				+ ds.getRoad()
				+ "\" landmark=\""
				+ ds.getLandmark()
				+ "\" range=\""
				+ ds.getRange()
				+ "\" bus=\""
				+ ds.getBus()
				+ "\" parking=\""
				+ ds.getParking()
				+ "\" purpose=\""
				+ this.getNodeValue(ds.getPurpose(), 8, this.getDictDAO(),
						false) + "\" service=\"" + ds.getService()
				+ "\" description=\"" + ds.getDescription() + "\" pic3=\""
				+ ds.getPic3() + "\" pic4=\"" + ds.getPic4() + "\" pic5=\""
				+ ds.getPic5() + "\" pic6=\"" + ds.getPic6() + "\" pic7=\""
				+ ds.getPic7() + "\" pic8=\"" + ds.getPic8() + "\" >");
		sbf.append("</shop></root>");
	}

	public void goodInfo(HttpServletRequest request, DdShopgoods ds,
			StringBuffer sbf) {
		String str = ds.getDescription();
		DdShop dshop = this.getDdShopDAO().findById(ds.getShopid());
		str = str.replaceAll("\n\n", "\n");
		str = str.replaceAll("\n", "-br-");
		float price2 = 0F;
		String price2des = "";
		if (dshop.getDiscountend() != null) {
			if (dshop.getDiscountend().getTime() > (new Date().getTime())) {
				price2 = ds.getPrice2();
				price2des = dshop.getDiscountremark();
			}
		}
		sbf.append("<good gtype=\"" + ds.getStyleType() + "\"  id=\""
				+ ds.getId() + "\" shopid=\"" + ds.getShopid()
				+ "\" shopname=\"" + ds.getShopname() + "\" name=\""
				+ ds.getName() + "\" price=\"" + ds.getPrice() + "\" price2=\""
				+ price2 + "\" price2des=\"" + price2des + "\" discount=\""
				+ ds.getDiscount() + "\"  price6=\"" + ds.getPrice6()
				+ "\" discount6=\"" + ds.getDiscount6() + "\"  price8=\""
				+ ds.getPrice8() + "\" discount8=\"" + ds.getDiscount8()
				+ "\"  price10=\"" + ds.getPrice10() + "\" discount10=\""
				+ ds.getDiscount10() + "\"  price12=\"" + ds.getPrice12()
				+ "\" discount12=\"" + ds.getDiscount12() + "\" fullres=\""
				+ ds.getFulldes() + "\" sending=\"" + dshop.getService()
				+ "\" style=\"" + ds.getStylevalue() + "\" sendto=\""
				+ ds.getSendtovalue() + "\" address = \"" + dshop.getAddress()
				+ "\" phone=\"" + dshop.getPhone() + "\" purpose=\""
				+ ds.getPurposevalue() + "\" description=\"" + str
				+ "\" pic3=\"" + ds.getPic3() + "\" pic4=\"" + ds.getPic4()
				+ "\" pic5=\"" + ds.getPic5() + "\" pic6=\"" + ds.getPic6()
				+ "\" pic7=\"" + ds.getPic7() + "\" pic8=\"" + ds.getPic8()
				+ "\"  >");
		sbf.append("</good></root>");
		// System.out.println(sbf.toString());
	}

	// 运动
	public void shopInfo4(HttpServletRequest request, DdShop ds,
			StringBuffer sbf) {
		Dict dict = this.getDictDAO().findByTypeAndCode(11, ds.getCost());
		sbf.append("<shop  id=\""
				+ ds.getId()
				+ "\" name=\""
				+ ds.getName()
				+ "\" shophours=\""
				+ ds.getShophours()
				+ "\" phone=\""
				+ ds.getPhone()
				+ "\"  moblie=\""
				+ ds.getMobile()
				+ "\" address=\""
				+ ds.getAddress()
				+ "\" cost=\""
				+ dict.getNodeValue()
				+ "\" area=\""
				+ ds.getArea()
				+ "\" road=\""
				+ ds.getRoad()
				+ "\" landmark=\""
				+ ds.getLandmark()
				+ "\" range=\""
				+ ds.getRange()
				+ "\" bus=\""
				+ ds.getBus()
				+ "\" parking=\""
				+ ds.getParking()
				+ "\" purpose=\""
				+ this.getNodeValue(ds.getPurpose(), 10, this.getDictDAO(),
						false) + "\" service=\"" + ds.getService()
				+ "\" description=\"" + ds.getDescription() + "\" pic3=\""
				+ ds.getPic3() + "\" pic4=\"" + ds.getPic4() + "\" pic5=\""
				+ ds.getPic5() + "\" pic6=\"" + ds.getPic6() + "\" pic7=\""
				+ ds.getPic7() + "\" pic8=\"" + ds.getPic8() + "\" >");
		sbf.append("</shop></root>");
	}

	public void newShop(HttpServletRequest request, DdShop ds, StringBuffer sbf) {
		String syslogid = request.getParameter("syslogid");
		DdSystemuser dduser1 = this.getDdSystemuserDAO().findByLogid(syslogid);
		if (dduser1 != null) {
			sbf.append("<result>2</result></root>");
			return;
		}
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录
		ds.setEditer(logid);
		ds.setIsbooking(1);
		ds.setIscoupon(1);
		if (request.getParameter("type") != null) {
			ds.setType(Integer.parseInt(request.getParameter("type")));
		}
		int purposetype = 4;
		if (ds.getType().intValue() == 1) {
			purposetype = 4;
		} else if (ds.getType().intValue() == 2) {
			purposetype = 6;
		} else if (ds.getType().intValue() == 3) {
			purposetype = 8;
		} else if (ds.getType().intValue() == 4) {
			purposetype = 10;
		} else {
			purposetype = 12;
		}

		if (request.getParameter("bookprice") != null) {
			ds
					.setBookprice(Float.parseFloat(request
							.getParameter("bookprice")));
		}

		if (request.getParameter("bookpricedes") != null) {
			ds.setBookpricedes(request.getParameter("bookpricedes"));
		}
		if (request.getParameter("bookpriceused") != null) {
			ds.setBookpriceuse(request.getParameter("bookpriceused"));
		}
		if (request.getParameter("bookreq") != null) {
			ds.setBookreq(request.getParameter("bookreq"));
		}
		if (request.getParameter("wifi") != null) {
			ds.setWifi(Integer.parseInt(request.getParameter("wifi")));
		}
		if (request.getParameter("visa") != null) {
			ds.setVisa(Integer.parseInt(request.getParameter("visa")));
		}
		if (request.getParameter("park") != null) {
			ds.setPark(Integer.parseInt(request.getParameter("park")));
		}
		if (request.getParameter("bankacc") != null) {
			ds.setBankacc(request.getParameter("bankacc"));
		}
		if (request.getParameter("bankaccname") != null) {
			ds.setBankaccname(request.getParameter("bankaccname"));
		}
		if (request.getParameter("bossphone") != null) {
			ds.setBossphone(request.getParameter("bossphone"));
		}
		if (request.getParameter("coupon3") != null) {
			ds.setCoupon3(request.getParameter("coupon3"));
		}
		if (request.getParameter("enddate") != null
				&& !request.getParameter("enddate").equals("")) {
			ds.setEnddate(DateStrFormat.getDateByString(request
					.getParameter("enddate")));
		}
		if (request.getParameter("loge") != null) {
			ds.setLoge(Integer.parseInt(request.getParameter("loge")));
			if (request.getParameter("loge").equals("1")) {
				ds.setLoge0(1);
				ds.setLoge1(1);
			}
			if (request.getParameter("loge").equals("2")) {
				ds.setLoge0(1);
				ds.setLoge1(0);
			}
			if (request.getParameter("loge").equals("3")) {
				ds.setLoge0(0);
				ds.setLoge1(1);
			}
		}

		if (request.getParameter("cost") != null) {
			ds.setCost(Integer.parseInt(request.getParameter("cost")));
		}
		if (request.getParameter("belong") != null) {
			ds.setBelong(Integer.parseInt(request.getParameter("belong")));
		}
		if (request.getParameter("name") != null) {
			ds.setName(request.getParameter("name"));
		}
		if (request.getParameter("shophours") != null) {
			ds.setShophours(request.getParameter("shophours"));
		}
		if (request.getParameter("style") != null) {
			ds.setStyle(Long.parseLong(request.getParameter("style")));
		}

		if (request.getParameter("discount") != null) {
			ds.setDiscount(Float.parseFloat(request.getParameter("discount")));
		}
		String stylestr = "";
		if (request.getParameter("styletype") != null
				&& request.getParameter("styletype").length() > 0) {
			ds
					.setStyleType(Integer.parseInt(request
							.getParameter("styletype")));
			if (ds.getType() != 5) {
				Dict d = (Dict) this.getDictDAO().findByNodeCode(
						ds.getStyleType()).get(0);
				stylestr = d.getNodeValue() + ",";
			}
		}
		if (request.getParameter("phone") != null) {
			ds.setPhone(request.getParameter("phone"));
		}
		if (request.getParameter("mobile") != null) {
			ds.setMobile(request.getParameter("mobile"));
		}

		if (request.getParameter("address") != null) {
			ds.setAddress(request.getParameter("address"));
		}
		if (request.getParameter("area") != null) {
			ds.setArea(request.getParameter("area"));
		}
		if (request.getParameter("landmark") != null) {
			ds.setLandmark(request.getParameter("landmark"));
		}
		if (request.getParameter("bus") != null) {
			ds.setBus(request.getParameter("bus"));
		}
		if (request.getParameter("posx") != null) {
			ds.setPosx(request.getParameter("posx").trim());
		}
		if (request.getParameter("posy") != null) {
			ds.setPosy(request.getParameter("posy").trim());
		}
		if (request.getParameter("posx_g") != null) {
			ds.setPosx_g(request.getParameter("posx_g").trim());
		}
		if (request.getParameter("posy_g") != null) {
			ds.setPosy_g(request.getParameter("posy_g").trim());
		}
		if (request.getParameter("purpose") != null) {
			ds.setPurpose(Integer.parseInt(request.getParameter("purpose")));
		}
		if (request.getParameter("description") != null) {
			ds.setDescription(request.getParameter("description"));
		}

		if (request.getParameter("pricedivide") != null) {
			ds.setPricedivide(request.getParameter("pricedivide"));
		}
		if (request.getParameter("id") != null
				&& request.getParameter("id").length() > 0) {
		}
		String style_str = request.getParameter("style_str");
		if (style_str != null && style_str.trim().length() > 0) {
			String str[] = style_str.split(",");

			for (int i = 0; i < str.length; i++) {
				if (str[i] != null && str[i].length() > 0) {
					Dict d = (Dict) this.getDictDAO().findByTypeAndCode(2,
							ds.getStyleType(), Integer.parseInt(str[i]));
					stylestr = stylestr + d.getNodeValue() + ",";
				}
			}
			if (stylestr.length() > 0) {
				stylestr = stylestr.substring(0, stylestr.length() - 1);
			}
			ds.setStylevalue(stylestr);
		}
		String purpose_str = request.getParameter("purpose_str");
		if (purpose_str != null && purpose_str.trim().length() > 0) {
			String str1[] = purpose_str.split(",");
			String purposestr = "";
			for (int i = 0; i < str1.length; i++) {
				if (str1[i] != null && str1[i].length() > 0) {
					Dict d = (Dict) this.getDictDAO().findByTypeAndCode(
							purposetype, Integer.parseInt(str1[i]));
					purposestr = purposestr + d.getNodeValue() + ",";
				}
			}
			if (purposestr.length() > 0) {
				purposestr = purposestr.substring(0, purposestr.length() - 1);
			}
			ds.setPurposevalue(purposestr);
		}
		ds
				.setEditer((Integer) request.getSession().getAttribute(
						"systemlogid"));
		ds.setHot(new Random().nextInt(100)+100);
		this.getDdShopDAO().saveOrUpdate(ds);
		DdSystemuser dduser = new DdSystemuser();
		dduser.setLogid(request.getParameter("syslogid"));
		dduser.setName(ds.getName());
		dduser.setPassword(request.getParameter("syslogpas"));
		dduser.setShopid(ds.getId());
		dduser.setType(6);
		this.getDdSystemuserDAO().save(dduser);
		sbf.append("<result>1</result></root>");
		return;
	}

	public void editShop(HttpServletRequest request, DdShop ds, StringBuffer sbf) {
		String syslogid = request.getParameter("syslogid");
		ds = this.getDdShopDAO().findById(ds.getId());
		if (ds.getCreatedate() == null) {
			ds.setCreatedate(new Date());
		}
		if (request.getParameter("type") != null) {
			ds.setType(Integer.parseInt(request.getParameter("type")));
		}
		int purposetype = 4;
		if (ds.getType().intValue() == 1) {
			purposetype = 4;
		} else if (ds.getType().intValue() == 2) {
			purposetype = 6;
		} else if (ds.getType().intValue() == 3) {
			purposetype = 8;
		} else if (ds.getType().intValue() == 4) {
			purposetype = 10;
		} else {
			purposetype = 12;
		}
		if (request.getParameter("bookprice") != null) {
			ds
					.setBookprice(Float.parseFloat(request
							.getParameter("bookprice")));
		}

		if (request.getParameter("bookpricedes") != null) {
			ds.setBookpricedes(request.getParameter("bookpricedes"));
		}
		if (request.getParameter("bookpriceused") != null) {
			ds.setBookpriceuse(request.getParameter("bookpriceused"));
		}
		if (request.getParameter("bookreq") != null) {
			ds.setBookreq(request.getParameter("bookreq"));
		}
		if (request.getParameter("wifi") != null) {
			ds.setWifi(Integer.parseInt(request.getParameter("wifi")));
		}
		if (request.getParameter("visa") != null) {
			ds.setVisa(Integer.parseInt(request.getParameter("visa")));
		}
		if (request.getParameter("park") != null) {
			ds.setPark(Integer.parseInt(request.getParameter("park")));
		}
		if (request.getParameter("bankacc") != null) {
			ds.setBankacc(request.getParameter("bankacc"));
		}
		if (request.getParameter("bankaccname") != null) {
			ds.setBankaccname(request.getParameter("bankaccname"));
		}
		if (request.getParameter("bossphone") != null) {
			ds.setBossphone(request.getParameter("bossphone"));
		}
		if (request.getParameter("coupon3") != null) {
			ds.setCoupon3(request.getParameter("coupon3"));
		}
		if (request.getParameter("enddate") != null
				&& !request.getParameter("enddate").equals("")) {
			ds.setEnddate(DateStrFormat.getDateByString(request
					.getParameter("enddate")));
		}
		if (request.getParameter("loge") != null) {
			ds.setLoge(Integer.parseInt(request.getParameter("loge")));
			if (request.getParameter("loge").equals("1")) {
				ds.setLoge0(1);
				ds.setLoge1(1);
			}
			if (request.getParameter("loge").equals("2")) {
				ds.setLoge0(1);
				ds.setLoge1(0);
			}
			if (request.getParameter("loge").equals("3")) {
				ds.setLoge0(0);
				ds.setLoge1(1);
			}
		}
		if (request.getParameter("cost") != null) {
			ds.setCost(Integer.parseInt(request.getParameter("cost")));
		}
		if (request.getParameter("belong") != null) {
			ds.setBelong(Integer.parseInt(request.getParameter("belong")));
		}
		if (request.getParameter("name") != null) {
			ds.setName(request.getParameter("name"));
		}
		if (request.getParameter("shophours") != null) {
			ds.setShophours(request.getParameter("shophours"));
		}
		if (request.getParameter("style") != null) {
			ds.setStyle(Long.parseLong(request.getParameter("style")));
		}

		if (request.getParameter("discount") != null) {
			ds.setDiscount(Float.parseFloat(request.getParameter("discount")));
		}
		if (request.getParameter("posx") != null) {
			ds.setPosx(request.getParameter("posx").trim());
		}
		if (request.getParameter("posy") != null) {
			ds.setPosy(request.getParameter("posy").trim());
		}
		if (request.getParameter("posx_g") != null) {
			ds.setPosx_g(request.getParameter("posx_g").trim());
		}
		if (request.getParameter("posy_g") != null) {
			ds.setPosy_g(request.getParameter("posy_g").trim());
		}
		String stylestr = "";
		if (request.getParameter("styletype") != null
				&& request.getParameter("styletype").length() > 0) {
			ds
					.setStyleType(Integer.parseInt(request
							.getParameter("styletype")));
			if (ds.getType() != 5) {
				Dict d = (Dict) this.getDictDAO().findByNodeCode(
						ds.getStyleType()).get(0);
				stylestr = d.getNodeValue();
			}
		}
		if (request.getParameter("phone") != null) {
			ds.setPhone(request.getParameter("phone"));
		}

		if (request.getParameter("address") != null) {
			ds.setAddress(request.getParameter("address"));
		}
		if (request.getParameter("area") != null) {
			ds.setArea(request.getParameter("area"));
		}
		if (request.getParameter("road") != null) {
			ds.setRoad(request.getParameter("road"));
		}
		if (request.getParameter("landmark") != null) {
			ds.setLandmark(request.getParameter("landmark"));
		}
		if (request.getParameter("bus") != null) {
			ds.setBus(request.getParameter("bus"));
		}
		if (request.getParameter("purpose") != null) {
			ds.setPurpose(Integer.parseInt(request.getParameter("purpose")));
		}
		if (request.getParameter("description") != null) {
			ds.setDescription(request.getParameter("description"));
		}
		if (request.getParameter("name1") != null) {
			ds.setName1(request.getParameter("name1"));
		}
		if (request.getParameter("url") != null) {
			ds.setUrl(request.getParameter("url"));
		}
		if (request.getParameter("title") != null) {
			ds.setTitle(request.getParameter("title"));
		}
		if (request.getParameter("keyword") != null) {
			ds.setKeyword(request.getParameter("keyword"));
		}
		if (request.getParameter("des") != null) {
			ds.setDes(request.getParameter("des"));
		}
		if (request.getParameter("pricedivide") != null) {
			ds.setPricedivide(request.getParameter("pricedivide"));
		}
		if (request.getParameter("mobile") != null) {
			ds.setMobile(request.getParameter("mobile"));
		}
		String style_str = request.getParameter("style_str");
		if (style_str != null && style_str.trim().length() > 0) {
			String str[] = style_str.split(",");

			for (int i = 0; i < str.length; i++) {
				if (str[i] != null && str[i].length() > 0) {
					Dict d = (Dict) this.getDictDAO().findByTypeAndCode(2,
							ds.getStyleType(), Integer.parseInt(str[i]));
					stylestr = stylestr + d.getNodeValue() + ",";
				}
			}
			if (stylestr.length() > 0) {
				stylestr = stylestr.substring(0, stylestr.length() - 1);
			}
			ds.setStylevalue(stylestr);

		}
		String purpose_str = request.getParameter("purpose_str");
		if (purpose_str != null && purpose_str.trim().length() > 0) {
			String str1[] = purpose_str.split(",");
			String purposestr = "";
			for (int i = 0; i < str1.length; i++) {
				if (str1[i] != null && str1[i].length() > 0) {
					Dict d = (Dict) this.getDictDAO().findByTypeAndCode(
							purposetype, Integer.parseInt(str1[i]));
					purposestr = purposestr + d.getNodeValue() + ",";
				}
			}
			if (purposestr.length() > 0) {
				purposestr = purposestr.substring(0, purposestr.length() - 1);
			}
			ds.setPurposevalue(purposestr);
		}
		if (request.getParameter("syslogid") != null) {
			DdSystemuser dduser = this.getDdSystemuserDAO().findByShopid(
					ds.getId());
			if (dduser == null) {
				dduser = new DdSystemuser();
				dduser.setLogid(request.getParameter("syslogid"));
				dduser.setName(ds.getName());
				dduser.setPassword(request.getParameter("syslogpas"));
				dduser.setShopid(ds.getId());
				dduser.setType(6);
				this.getDdSystemuserDAO().save(dduser);
			} else {
				dduser.setLogid(request.getParameter("syslogid"));
				dduser.setPassword(request.getParameter("syslogpas"));
				this.getDdSystemuserDAO().save(dduser);
			}

		}
		this.getDdShopDAO().saveOrUpdate(ds);

		sbf.append("<result>1</result></root>");
	}

	public void newGood(HttpServletRequest request, DdShopgoods dsg,
			StringBuffer sbf) {

		if (request.getParameter("type") != null) {
			dsg.setType(request.getParameter("type"));
		}
		if (request.getParameter("shopid") != null) {
			dsg.setShopid(Integer.parseInt(request.getParameter("shopid")));
		}
		if (request.getParameter("name") != null) {
			dsg.setName(request.getParameter("name"));
		}
		if (request.getParameter("description") != null) {
			dsg.setDescription(request.getParameter("description"));
		}
		if (request.getParameter("pic1") != null) {
			dsg.setPic1(request.getParameter("pic1"));
		}
		if (request.getParameter("pic2") != null) {
			dsg.setPic2(request.getParameter("pic2"));
		}
		if (request.getParameter("pic3") != null) {
			dsg.setPic3(request.getParameter("pic3"));
		}
		this.getDdGoodDAO().saveOrUpdate(dsg);
		sbf.append("<result>1</result></root>");
	}

	public void editGood(HttpServletRequest request, DdShopgoods dsg,
			StringBuffer sbf) {

		if (request.getParameter("type") != null) {
			dsg.setType(request.getParameter("type"));
		}
		if (request.getParameter("name") != null) {
			dsg.setName(request.getParameter("name"));
		}
		if (request.getParameter("description") != null) {
			dsg.setDescription(request.getParameter("description"));
		}
		if (request.getParameter("pic1") != null) {
			dsg.setPic1(request.getParameter("pic1"));
		}
		if (request.getParameter("pic2") != null) {
			dsg.setPic2(request.getParameter("pic2"));
		}
		if (request.getParameter("pic3") != null) {
			dsg.setPic3(request.getParameter("pic3"));
		}
		this.getDdGoodDAO().saveOrUpdate(dsg);
		sbf.append("<result>1</result></root>");
	}

	public void addfirstpage(HttpServletRequest request, StringBuffer sbf) {
		DdFirstPage dfp = this.getDdShopDAO().findFirstPageByShopid(
				Integer.parseInt(request.getParameter("shopid")));
		if (dfp != null) {
			sbf.append("<result>2</result></root>");
			return;
		}
		DdShop ds = this.getDdShopDAO().findById(
				Integer.parseInt(request.getParameter("shopid")));
		if (ds == null) {
			sbf.append("<result>3</result></root>");
			return;
		}
		dfp = new DdFirstPage();
		dfp.setShopid(Integer.parseInt(request.getParameter("shopid")));
		dfp.setType(ds.getType());
		dfp.setAddDate(new Date());
		dfp.setRemark(request.getParameter("remark") == null ? "" : request
				.getParameter("remark"));
		this.getDdShopDAO().saveOrUpdateFirstPage(dfp);
		sbf.append("<result>1</result></root>");
	}

	public void findentertainment(HttpServletRequest request, StringBuffer sbf) {
		long l1 = System.currentTimeMillis();
		String pageno = request.getParameter("pageno");
		String pagesize = request.getParameter("pagesize");
		String query = request.getParameter("query") == null ? "" : request
				.getParameter("query");
		if (pageno == null || pagesize == null || Integer.parseInt(pageno) < 1
				|| Integer.parseInt(pagesize) < 1) {
			sbf.append("<error>-2</error></root>");
			return;
		}
		String purpose = request.getParameter("purpose");
		String cost = request.getParameter("cost");
		String area = request.getParameter("area");
		String road = request.getParameter("road");
		String addQuery = "";
		if (area != null && !area.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(1, area);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and area=" + code;
				area = code + "";
			} else {
				area = null;
			}
		}
		if (road != null && !road.equals("")) {
			addQuery = addQuery + " and road='" + road + "'";
		}
		if (cost != null && !cost.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(5, cost);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and cost=" + code;
				cost = code + "";
			} else {
				cost = null;
			}
		}
		if (purpose != null && !purpose.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(6, purpose);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and " + code + "&purpose=" + code;
			}

		}
		PageList list = this.getDdShopDAO().findbypage(query,
				Integer.parseInt(pageno), Integer.parseInt(pagesize), addQuery,
				null, 2);
		if (list.getTotalCount() != 0 && query.length() > 1) {
			DdKeyword dk = this.getDdKeywordDAO().findByKeyword(query, 2);
			if (dk == null) {
				dk = new DdKeyword();
				dk.setKeyword(query);
				dk.setTypes(2);
				dk.setKeyword2(PubFun.getStringPinYin(query));
				dk.setKeyword3(PubFun.getStringPinYin2(query));
				dk.setHitnum(0);
				dk.setRecord(list.getTotalCount());
			}
			dk.setHitnum(dk.getHitnum() + 1);
			this.getDdKeywordDAO().saveOrUpdate(dk);
		}
		sbf.append("<shops total=\"" + list.getTotalCount() + "\">");
		for (int i = 0; i < list.size(); i++) {
			DdShop ds = (DdShop) list.get(i);
			Dict dict = this.getDictDAO().findByTypeAndCode(6, ds.getPurpose());
			sbf.append("<shop  id=\""
					+ ds.getId()
					+ "\" name=\""
					+ ds.getName()
					+ "\" shophours=\""
					+ ds.getShophours()
					+ "\" phone=\""
					+ ds.getPhone()
					+ "\"  purpose=\""
					+ this.getNodeValue(ds.getPurpose(), 6, this.getDictDAO(),
							false) + "\" address=\"" + ds.getAddress()
					+ "\" description=\"" + ds.getDescription() + "\" pic2=\""
					+ ds.getPic2() + "\" url=\"" + ds.getUrl() + "\"   />");
		}
		sbf.append("</shops>");
		// 区域汇总
		List list_area = this.getDdNodeDAO().getCountAreaData(
				list.getQueryString());
		sbf.append("<area>");
		if (area == null || area.equals("")) {
			for (int i = 0; i < list_area.size(); i++) {
				List list_tmp = (List) list_area.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</area>");
		// 根据目的(KTV,98...)
		List list_purpose = this.getDdNodeDAO().getCountPurposeData(
				list.getQueryString(), 6);
		sbf.append("<purpose>");
		if (purpose == null || purpose.equals("")) {
			for (int i = 0; i < list_purpose.size(); i++) {
				List list_tmp = (List) list_purpose.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</purpose>");
		// 根据人均
		List list_cost = this.getDdNodeDAO().getCountCostData(
				list.getQueryString(), 7);
		sbf.append("<cost>");
		if (cost == null || cost.equals("")) {
			for (int i = 0; i < list_cost.size(); i++) {
				List list_tmp = (List) list_cost.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}

		}
		sbf.append("</cost>");
		// 根据服务范围

		sbf.append("</root>");
		// System.out.println("total use " + (System.currentTimeMillis() - l1));
	}

	public void findrestaurant2(HttpServletRequest request, StringBuffer sbf)
			throws Exception {
		String pageno = request.getParameter("pageno");
		String pagesize = request.getParameter("pagesize");
		String query = request.getParameter("query") == null ? "" : request
				.getParameter("query");
		if (pageno == null || pagesize == null || Integer.parseInt(pageno) < 1
				|| Integer.parseInt(pagesize) < 1) {
			sbf.append("<error>2</error></root>");
			return;
		}
		String purpose = request.getParameter("purpose");
		String style = request.getParameter("style");
		String styletype = "";
		if (style != null && !style.equals("")) {
			Dict dict_tmp = this.getDictDAO().findByTypeAndValue(2, style);
			if (dict_tmp != null && dict_tmp.getRootNode().intValue() == 0) {
				styletype = style;
				style = "";
			} else if (dict_tmp != null
					&& dict_tmp.getRootNode().intValue() != 0) {
				dict_tmp = this.getDictDAO().findById(dict_tmp.getRootNode());
				styletype = dict_tmp.getNodeValue();
			}
		}
		String cost = request.getParameter("cost");
		String area = request.getParameter("area");
		String road = request.getParameter("road");
		String addQuery = "";
		if (area != null && !area.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(1, area);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and area=" + code;
				area = code + "";
			} else {
				area = null;
			}
		}
		if (road != null && !road.equals("")) {
			addQuery = addQuery + " and road='" + road + "'";
		}
		if (cost != null && !cost.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(5, cost);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and cost=" + code;
				cost = code + "";
			} else {
				cost = null;
			}
		}
		if (purpose != null && !purpose.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(4, purpose);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and " + code + "&purpose=" + code;
			}

		}
		if (style != null && !style.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(2, style);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and " + code + "&style=" + code;
			}
		}
		if (styletype != null && !styletype.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(2, styletype);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and styletype=" + code;
				styletype = code + "";
			} else {
				styletype = null;
			}
		}
		PageList list = this.getDdShopDAO().findbypage(query,
				Integer.parseInt(pageno), Integer.parseInt(pagesize), addQuery,
				null, 1);
		if (list.getTotalCount() != 0 && query.length() > 1) {
			DdKeyword dk = this.getDdKeywordDAO().findByKeyword(query, 1);
			if (dk == null) {
				dk = new DdKeyword();
				dk.setKeyword(query);
				dk.setTypes(1);
				dk.setKeyword2(PubFun.getStringPinYin(query));
				dk.setKeyword3(PubFun.getStringPinYin2(query));
				dk.setHitnum(0);
				dk.setRecord(list.getTotalCount());

			}
			dk.setHitnum(dk.getHitnum() + 1);
			this.getDdKeywordDAO().saveOrUpdate(dk);
		}
		sbf.append("<shops total=\"" + list.getTotalCount() + "\">");
		for (int i = 0; i < list.size(); i++) {
			DdShop ds = (DdShop) list.get(i);
			String discount = "";
			if (ds.getDiscountend() != null) {
				if (ds.getDiscountend().getTime() > (new Date().getTime())) {
					discount = ds.getDiscountremark();
				}
			}
			String discountvalue = "";
			if (ds.getDiscount() != null && ds.getDiscount() > 0) {
				discountvalue = ds.getDiscount() + "折";
			}
			sbf.append("<shop  id=\""
					+ ds.getId()
					+ "\" name=\""
					+ ds.getName()
					+ "\" issend=\""
					+ ds.getIssend()
					+ "\" isbooking=\""
					+ ds.getIsbooking()
					+ "\" shophours=\""
					+ ds.getShophours()
					+ "\"  style=\""
					+ this.getStyleValue(ds.getStyleType(), ds.getStyle(), this
							.getDictDAO())
					+ "\" phone=\""
					+ ds.getPhone()
					+ "\"   purpose=\""
					+ this.getNodeValue(ds.getPurpose(), 4, this.getDictDAO(),
							false) + "\" address=\"" + ds.getAddress()
					+ "\" description=\"" + ds.getDescription() + "\" pic2=\""
					+ ds.getPic2() + "\" url=\"" + ds.getUrl() + "\" title=\""
					+ ds.getTitle() + "\" keyword=\"" + ds.getKeyword()
					+ "\" discount=\"" + discount + "\" discountvalue=\""
					+ discountvalue + "\" />");
		}
		sbf.append("</shops>");
		// 区域汇总
		List list_area = this.getDdNodeDAO().getCountAreaData(
				list.getQueryString());
		sbf.append("<area>");
		if (area == null || area.equals("")) {
			for (int i = 0; i < list_area.size(); i++) {
				List list_tmp = (List) list_area.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</area>");
		// 根据目的
		List list_purpose = this.getDdNodeDAO().getCountPurposeData(
				list.getQueryString(), 4);
		// System.out.println(list.getQueryString());
		sbf.append("<purpose>");
		if (purpose == null || purpose.equals("")) {
			for (int i = 0; i < list_purpose.size(); i++) {
				List list_tmp = (List) list_purpose.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}

		sbf.append("</purpose>");
		// 根据菜系 --分为主.子两棵树--当源查询条件中不含菜系查询条件情况下返回主树(一级菜单)
		// 当 源查询条件中含菜系查询条件情况下返回子树(二级菜单)
		sbf.append("<style>");
		if (styletype == null || styletype.equals("")) { // 没传餐厅类别,返回餐厅类别汇总树
			List list_style = this.getDdNodeDAO().getCountStyleData(
					list.getQueryString());
			for (int i = 0; i < list_style.size(); i++) {
				List list_tmp = (List) list_style.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		} else { // 已经传入餐厅类别,返回菜系子树(如果已经传入菜系子树,不返回树)
			if (style == null || style.equals("")) {
				List list_style = this.getDdNodeDAO().getCountStyleChildData(
						list.getQueryString(), styletype, "dd_shop");
				for (int i = 0; i < list_style.size(); i++) {
					List list_tmp = (List) list_style.get(i);
					sbf.append("<item value=\"" + list_tmp.get(0)
							+ "\" count=\"" + list_tmp.get(1) + "\" />");
				}
			}
		}
		sbf.append("</style>");
		// 根据人均

		List list_cost = this.getDdNodeDAO().getCountCostData(
				list.getQueryString(), 5);
		sbf.append("<cost>");
		if (cost == null || cost.equals("")) {
			for (int i = 0; i < list_cost.size(); i++) {
				List list_tmp = (List) list_cost.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}

		}
		sbf.append("</cost>");
		// 根据服务范围

		sbf.append("</root>");
		// System.out.println("total use " + (System.currentTimeMillis() - l1));
	}

	public void findrestaurant(HttpServletRequest request, StringBuffer sbf)
			throws Exception {
		String pageno = request.getParameter("pageno");
		String pagesize = request.getParameter("pagesize");
		String query = request.getParameter("query") == null ? "" : request
				.getParameter("query");
		if (pageno == null || pagesize == null || Integer.parseInt(pageno) < 1
				|| Integer.parseInt(pagesize) < 1) {
			sbf.append("<error>2</error></root>");
			return;
		}
		String purpose = request.getParameter("purpose");
		String style = request.getParameter("style");
		String styletype = "";
		if (style != null && !style.equals("")) {
			Dict dict_tmp = this.getDictDAO().findByTypeAndValue(2, style);
			if (dict_tmp != null && dict_tmp.getRootNode().intValue() == 0) {
				styletype = style;
				style = "";
			} else if (dict_tmp != null
					&& dict_tmp.getRootNode().intValue() != 0) {
				dict_tmp = this.getDictDAO().findById(dict_tmp.getRootNode());
				styletype = dict_tmp.getNodeValue();
			}
		}
		String cost = request.getParameter("cost");
		String area = request.getParameter("area");
		String road = request.getParameter("road");
		String addQuery = "";
		if (area != null && !area.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(1, area);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and area=" + code;
				area = code + "";
			} else {
				area = null;
			}
		}
		if (road != null && !road.equals("")) {
			addQuery = addQuery + " and road='" + road + "'";
		}
		if (cost != null && !cost.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(5, cost);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and cost=" + code;
				cost = code + "";
			} else {
				cost = null;
			}
		}
		if (purpose != null && !purpose.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(4, purpose);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and " + code + "&purpose=" + code;
			}

		}
		if (style != null && !style.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(2, style);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and " + code + "&style=" + code;
			}
		}
		if (styletype != null && !styletype.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(2, styletype);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and styletype=" + code;
				styletype = code + "";
			} else {
				styletype = null;
			}
		}
		PageList list = this.getDdShopDAO().findbypage(query,
				Integer.parseInt(pageno), Integer.parseInt(pagesize), addQuery,
				null, 1);
		if (list.getTotalCount() != 0 && query.length() > 1) {
			DdKeyword dk = this.getDdKeywordDAO().findByKeyword(query, 1);
			if (dk == null) {
				dk = new DdKeyword();
				dk.setKeyword(query);
				dk.setTypes(1);
				dk.setKeyword2(PubFun.getStringPinYin(query));
				dk.setKeyword3(PubFun.getStringPinYin2(query));
				dk.setHitnum(0);
				dk.setRecord(list.getTotalCount());

			}
			dk.setHitnum(dk.getHitnum() + 1);
			this.getDdKeywordDAO().saveOrUpdate(dk);
		}
		sbf.append("<shops total=\"" + list.getTotalCount() + "\">");
		for (int i = 0; i < list.size(); i++) {
			DdShop ds = (DdShop) list.get(i);
			String discount = "";
			if (ds.getDiscountend() != null) {
				if (ds.getDiscountend().getTime() > (new Date().getTime())) {
					discount = ds.getDiscountremark();
				}
			}
			String discountvalue = "";
			if (ds.getDiscount() != null && ds.getDiscount() > 0) {
				discountvalue = ds.getDiscount() + "折";
			}
			sbf.append("<shop  id=\""
					+ ds.getId()
					+ "\" name=\""
					+ ds.getName()
					+ "\" issend=\""
					+ ds.getIssend()
					+ "\" isbooking=\""
					+ ds.getIsbooking()
					+ "\" shophours=\""
					+ ds.getShophours()
					+ "\"  style=\""
					+ this.getStyleValue(ds.getStyleType(), ds.getStyle(), this
							.getDictDAO())
					+ "\" phone=\""
					+ ds.getPhone()
					+ "\"   purpose=\""
					+ this.getNodeValue(ds.getPurpose(), 4, this.getDictDAO(),
							false) + "\" address=\"" + ds.getAddress()
					+ "\" description=\"" + ds.getDescription() + "\" pic2=\""
					+ ds.getPic2() + "\" url=\"" + ds.getUrl() + "\" title=\""
					+ ds.getTitle() + "\" keyword=\"" + ds.getKeyword()
					+ "\" discount=\"" + discount + "\" discountvalue=\""
					+ discountvalue + "\" />");
		}
		sbf.append("</shops>");
		// 区域汇总
		List list_area = this.getDdNodeDAO().getCountAreaData(
				list.getQueryString());
		sbf.append("<area>");
		if (area == null || area.equals("")) {
			for (int i = 0; i < list_area.size(); i++) {
				List list_tmp = (List) list_area.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</area>");
		// 根据目的
		List list_purpose = this.getDdNodeDAO().getCountPurposeData(
				list.getQueryString(), 4);
		// System.out.println(list.getQueryString());
		sbf.append("<purpose>");
		if (purpose == null || purpose.equals("")) {
			for (int i = 0; i < list_purpose.size(); i++) {
				List list_tmp = (List) list_purpose.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}

		sbf.append("</purpose>");
		// 根据菜系 --分为主.子两棵树--当源查询条件中不含菜系查询条件情况下返回主树(一级菜单)
		// 当 源查询条件中含菜系查询条件情况下返回子树(二级菜单)
		sbf.append("<style>");
		if (styletype == null || styletype.equals("")) { // 没传餐厅类别,返回餐厅类别汇总树
			List list_style = this.getDdNodeDAO().getCountStyleData(
					list.getQueryString());
			for (int i = 0; i < list_style.size(); i++) {
				List list_tmp = (List) list_style.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		} else { // 已经传入餐厅类别,返回菜系子树(如果已经传入菜系子树,不返回树)
			if (style == null || style.equals("")) {
				List list_style = this.getDdNodeDAO().getCountStyleChildData(
						list.getQueryString(), styletype, "dd_shop");
				for (int i = 0; i < list_style.size(); i++) {
					List list_tmp = (List) list_style.get(i);
					sbf.append("<item value=\"" + list_tmp.get(0)
							+ "\" count=\"" + list_tmp.get(1) + "\" />");
				}
			}
		}
		sbf.append("</style>");
		// 根据人均

		List list_cost = this.getDdNodeDAO().getCountCostData(
				list.getQueryString(), 5);
		sbf.append("<cost>");
		if (cost == null || cost.equals("")) {
			for (int i = 0; i < list_cost.size(); i++) {
				List list_tmp = (List) list_cost.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}

		}
		sbf.append("</cost>");
		// 根据服务范围

		sbf.append("</root>");
		// System.out.println("total use " + (System.currentTimeMillis() - l1));
	}

	public void findhotel(HttpServletRequest request, StringBuffer sbf) {
		long l1 = System.currentTimeMillis();
		String pageno = request.getParameter("pageno");
		String pagesize = request.getParameter("pagesize");
		String query = request.getParameter("query") == null ? "" : request
				.getParameter("query");
		if (pageno == null || pagesize == null || Integer.parseInt(pageno) < 1
				|| Integer.parseInt(pagesize) < 1) {
			sbf.append("<error>-2</error></root>");
			return;
		}
		String purpose = request.getParameter("purpose");
		String cost = request.getParameter("cost");
		String area = request.getParameter("area");
		String road = request.getParameter("road");
		String addQuery = "";
		if (area != null && !area.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(1, area);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and area=" + code;
				area = code + "";
			} else {
				area = null;
			}
		}
		if (road != null && !road.equals("")) {
			addQuery = addQuery + " and road='" + road + "'";
		}
		if (cost != null && !cost.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(7, cost);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and cost=" + code;
				cost = code + "";
			} else {
				cost = null;
			}
		}
		if (purpose != null && !purpose.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(8, purpose);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and " + code + "&purpose=" + code;
			}
		}
		PageList list = this.getDdShopDAO().findbypage(query,
				Integer.parseInt(pageno), Integer.parseInt(pagesize), addQuery,
				null, 3);
		sbf.append("<shops total=\"" + list.getTotalCount() + "\">");
		for (int i = 0; i < list.size(); i++) {
			DdShop ds = (DdShop) list.get(i);
			sbf.append("<shop  id=\""
					+ ds.getId()
					+ "\" name=\""
					+ ds.getName()
					+ "\" shophours=\""
					+ ds.getShophours()
					+ "\" phone=\""
					+ ds.getPhone()
					+ "\"  purpose=\""
					+ this.getNodeValue(ds.getPurpose(), 8, this.getDictDAO(),
							false) + "\" address=\"" + ds.getAddress()
					+ "\" description=\"" + ds.getDescription() + "\" pic2=\""
					+ ds.getPic2() + "\"  />");
		}
		sbf.append("</shops>");
		// 区域汇总
		List list_area = this.getDdNodeDAO().getCountAreaData(
				list.getQueryString());
		sbf.append("<area>");
		if (area == null || area.equals("")) {
			for (int i = 0; i < list_area.size(); i++) {
				List list_tmp = (List) list_area.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</area>");
		// 根据目的
		List list_purpose = this.getDdNodeDAO().getCountPurposeData(
				list.getQueryString(), 8);
		sbf.append("<purpose>");
		if (purpose == null || purpose.equals("")) {
			for (int i = 0; i < list_purpose.size(); i++) {
				List list_tmp = (List) list_purpose.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</purpose>");
		// 根据人均
		List list_cost = this.getDdNodeDAO().getCountCostData(
				list.getQueryString(), 7);
		sbf.append("<cost>");
		if (cost == null || cost.equals("")) {
			for (int i = 0; i < list_cost.size(); i++) {
				List list_tmp = (List) list_cost.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}

		}
		sbf.append("</cost>");
		// 根据服务范围
		sbf.append("</root>");
		// System.out.println("total use " + (System.currentTimeMillis() - l1));
	}

	public void findshopping(HttpServletRequest request, StringBuffer sbf) {
		long l1 = System.currentTimeMillis();
		String pageno = request.getParameter("pageno");
		String pagesize = request.getParameter("pagesize");
		String query = request.getParameter("query") == null ? "" : request
				.getParameter("query");
		if (pageno == null) {
			pageno = "1";
		}
		if (pagesize == null) {
			pagesize = "10";
		}
		if (pageno == null || pagesize == null || Integer.parseInt(pageno) < 1
				|| Integer.parseInt(pagesize) < 1) {
			sbf.append("<error>-2</error></root>");
			return;
		}
		String purpose = request.getParameter("purpose");
		String cost = request.getParameter("cost");
		String sendto = request.getParameter("sendto");
		String road = request.getParameter("road");
		String style = request.getParameter("style");
		String styletype = "";
		if (style != null && !style.equals("")) {
			Dict dict_tmp = this.getDictDAO().findByTypeAndValue(14, style);
			if (dict_tmp != null && dict_tmp.getRootNode().intValue() == 0) {
				styletype = style;
				style = "";
			} else if (dict_tmp != null
					&& dict_tmp.getRootNode().intValue() != 0) {
				dict_tmp = this.getDictDAO().findById(dict_tmp.getRootNode());
				styletype = dict_tmp.getNodeValue();
			}
		}
		String addQuery = "";
		if (sendto != null && !sendto.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(15, sendto);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and " + code + "&sendto=" + code;
				sendto = code + "";
			} else {
				sendto = null;
			}
		}
		if (road != null && !road.equals("")) {
			addQuery = addQuery + " and road like '" + road + "'";
		}
		if (cost != null && !cost.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(11, cost);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and cost=" + code;
				cost = code + "";
			} else {
				cost = null;
			}
		}
		if (purpose != null && !purpose.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(10, purpose);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and " + code + "&purpose=" + code;
			}

		}
		if (style != null && !style.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(14, style);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and " + code + "&style=" + code;
			}
		}
		if (styletype != null && !styletype.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(14, styletype);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and styletype=" + code;
				styletype = code + "";
			} else {
				styletype = null;
			}
		}
		PageList list = this.getDdShopDAO().findbypage1(query,
				Integer.parseInt(pageno), Integer.parseInt(pagesize), addQuery,
				null, 4);
		if (list.getTotalCount() != 0 && query.length() > 1) {
			DdKeyword dk = this.getDdKeywordDAO().findByKeyword(query, 4);
			if (dk == null) {
				dk = new DdKeyword();
				dk.setKeyword(query);
				dk.setTypes(4);
				dk.setKeyword2(PubFun.getStringPinYin(query));
				dk.setKeyword3(PubFun.getStringPinYin2(query));
				dk.setHitnum(0);
				dk.setRecord(list.getTotalCount());
			}
			dk.setHitnum(dk.getHitnum() + 1);
			this.getDdKeywordDAO().saveOrUpdate(dk);
		}
		sbf.append("<shops total=\"" + list.getTotalCount() + "\">");
		for (int i = 0; i < list.size(); i++) {
			DdShopgoods ds = (DdShopgoods) list.get(i);
			sbf.append("<shop  id=\""
					+ ds.getId()
					+ "\" name=\""
					+ ds.getName()
					+ "\" shopname=\""
					+ ds.getShopname()
					+ "\" price=\""
					+ ds.getPrice()
					+ "\" discount=\""
					+ ds.getDiscount()
					+ "\" purpose=\""
					+ this.getNodeValue(ds.getPurpose(), 10, this.getDictDAO(),
							false) + "\" description=\"" + ds.getDescription()
					+ "\" pic2=\"" + ds.getPic2() + "\" url=\"" + ds.getUrl()
					+ "\"  />");
		}
		sbf.append("</shops>");
		// 根据礼物大类 --分为主.子两棵树--当源查询条件中不含菜系查询条件情况下返回主树(一级菜单)
		// 当 源查询条件中含大类查询条件情况下返回子树(二级菜单)
		sbf.append("<style>");
		if (styletype == null || styletype.equals("")) { // 没传大类类别,返回大类类别汇总树
			List list_style = this.getDdNodeDAO().getCountStyleData1(
					list.getQueryString());
			for (int i = 0; i < list_style.size(); i++) {
				List list_tmp = (List) list_style.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		} else { // 已经传入大类类别,返回子类子树(如果已经传入子类子树,不返回树)
			if (style == null || style.equals("")) {
				List list_style = this.getDdNodeDAO().getCountStyleChildData1(
						list.getQueryString(), styletype, "dd_shop");
				for (int i = 0; i < list_style.size(); i++) {
					List list_tmp = (List) list_style.get(i);
					sbf.append("<item value=\"" + list_tmp.get(0)
							+ "\" count=\"" + list_tmp.get(1) + "\" />");
				}
			}
		}
		sbf.append("</style>");

		// 根据送给谁
		List list_sendto = this.getDdNodeDAO().getCountSendToData(
				list.getQueryString(), 15);
		sbf.append("<sendto>");
		if (sendto == null || sendto.equals("")) {
			for (int i = 0; i < list_sendto.size(); i++) {
				List list_tmp = (List) list_sendto.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</sendto>");
		// 根据目的
		List list_purpose = this.getDdNodeDAO().getCountPurposeData1(
				list.getQueryString(), 10);
		sbf.append("<purpose>");
		if (purpose == null || purpose.equals("")) {
			for (int i = 0; i < list_purpose.size(); i++) {
				List list_tmp = (List) list_purpose.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</purpose>");
		// 根据人均
		List list_cost = this.getDdNodeDAO().getCountCostData1(
				list.getQueryString(), 11);
		sbf.append("<cost>");
		if (cost == null || cost.equals("")) {
			for (int i = 0; i < list_cost.size(); i++) {
				List list_tmp = (List) list_cost.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}

		}
		sbf.append("</cost>");
		// 根据服务范围
		sbf.append("</root>");
		// System.out.println("total use " + (System.currentTimeMillis() - l1));
	}

	public void findsport(HttpServletRequest request, StringBuffer sbf) {
		long l1 = System.currentTimeMillis();
		String pageno = request.getParameter("pageno");
		String pagesize = request.getParameter("pagesize");
		String query = request.getParameter("query") == null ? "" : request
				.getParameter("query");
		if (pageno == null || pagesize == null || Integer.parseInt(pageno) < 1
				|| Integer.parseInt(pagesize) < 1) {
			sbf.append("<error>-2</error></root>");
			return;
		}
		String purpose = request.getParameter("purpose");
		String cost = request.getParameter("cost");
		String area = request.getParameter("area");
		String road = request.getParameter("road");
		String addQuery = "";
		if (area != null && !area.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(1, area);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and area=" + code;
				area = code + "";
			} else {
				area = null;
			}
		}
		if (road != null && !road.equals("")) {
			addQuery = addQuery + " and road='" + road + "'";
		}

		if (purpose != null && !purpose.equals("")) {
			Dict dict = this.getDictDAO().findByTypeAndValue(12, purpose);
			if (dict != null) {
				long code = dict.getNodeCode();
				addQuery = addQuery + " and purpose=" + code;
			}

		}
		PageList list = this.getDdShopDAO().findbypage(query,
				Integer.parseInt(pageno), Integer.parseInt(pagesize), addQuery,
				null, 5);
		if (list.getTotalCount() != 0 && query.length() > 1) {
			DdKeyword dk = this.getDdKeywordDAO().findByKeyword(query, 5);
			if (dk == null) {
				dk = new DdKeyword();
				dk.setKeyword(query);
				dk.setTypes(5);
				dk.setKeyword2(PubFun.getStringPinYin(query));
				dk.setKeyword3(PubFun.getStringPinYin2(query));
				dk.setHitnum(0);
				dk.setRecord(list.getTotalCount());
			}
			dk.setHitnum(dk.getHitnum() + 1);
			this.getDdKeywordDAO().saveOrUpdate(dk);
		}
		sbf.append("<shops total=\"" + list.getTotalCount() + "\">");
		for (int i = 0; i < list.size(); i++) {
			DdShop ds = (DdShop) list.get(i);
			sbf.append("<shop  id=\""
					+ ds.getId()
					+ "\" name=\""
					+ ds.getName()
					+ "\" address=\""
					+ ds.getAddress()
					+ "\" shophours=\""
					+ ds.getShophours()
					+ "\" phone=\""
					+ ds.getPhone()
					+ "\" bookprice=\""
					+ ds.getBookprice()
					+ "\" bookprice2=\""
					+ ds.getBookprice2()
					+ "\"  purpose=\""
					+ this.getNodeValue(ds.getPurpose(), 12, this.getDictDAO(),
							false) + "\"  description=\"" + ds.getDescription()
					+ "\" pic2=\"" + ds.getPic2() + "\" url=\"" + ds.getUrl()
					+ "\"  />");
		}
		sbf.append("</shops>");
		// 区域汇总
		List list_area = this.getDdNodeDAO().getCountAreaData(
				list.getQueryString());
		sbf.append("<area>");
		if (area == null || area.equals("")) {
			for (int i = 0; i < list_area.size(); i++) {
				List list_tmp = (List) list_area.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</area>");
		// 根据目的
		List list_purpose = this.getDdNodeDAO().getCountPurposeData(
				list.getQueryString(), 12);
		sbf.append("<purpose>");
		if (purpose == null || purpose.equals("")) {
			for (int i = 0; i < list_purpose.size(); i++) {
				List list_tmp = (List) list_purpose.get(i);
				sbf.append("<item value=\"" + list_tmp.get(0) + "\" count=\""
						+ list_tmp.get(1) + "\" />");
			}
		}
		sbf.append("</purpose>");

		// 根据服务范围
		sbf.append("</root>");
		// System.out.println("total use " + (System.currentTimeMillis() - l1));
	}

	public void removefirstpage(HttpServletRequest request, StringBuffer sbf) {
		DdFirstPage dfp = this.getDdShopDAO().findFirstPageByShopid(
				Integer.parseInt(request.getParameter("shopid")));
		if (dfp != null) {
			sbf.append("<result>2</result></root>");
			return;
		}
		this.getDdShopDAO().deleteFirstPage(dfp);
		sbf.append("<result>1</result></root>");
	}

	public void listfirstpage(HttpServletRequest request, StringBuffer sbf) {
		List li = this.getDdShopDAO().findFirstPage(
				Integer.parseInt(request.getParameter("type")));
		sbf.append("<shops>");
		for (int i = 0; i < li.size(); i++) {
			DdFirstPage dfp = (DdFirstPage) li.get(i);
			DdShop ds = this.getDdShopDAO().findById(dfp.getShopid());
			sbf.append("<shop id= \"" + ds.getId() + "\" name = \""
					+ ds.getName() + "\" adddate =\"" + dfp.getAddDate()
					+ "\"  />");
		}
		sbf.append("</shops>");
	}

	/**
	 * 获取地区
	 * 
	 * @return
	 */
	public List getArea() {
		return this.getDictDAO().findByRootNode(11100);
	}

	/**
	 * 餐厅消费目的
	 * 
	 * @return
	 */
	public List getCTPurpose() {
		return this.getDictDAO().findByType(4);
	}

	/**
	 * 赠予对象
	 * 
	 * @return
	 */
	public List getScSendto() {
		return this.getDictDAO().findByType(15);
	}

	/**
	 * 餐厅类型
	 * 
	 * @return
	 */
	public List getCTStyletype() {
		return this.getDictDAO().findByTypeAndRoot(2, 0);
	}

	/**
	 * 商城类型
	 * 
	 * @return
	 */
	public List getScStyletype() {
		return this.getDictDAO().findByTypeAndRoot(14, 0);
	}

	/**
	 * 餐厅菜系
	 * 
	 * @return
	 */
	public List getCTStyle(int styletype) {
		return this.getDictDAO().findByTypeAndRoot(2, styletype);
	}

	/**
	 * 商城商品类型
	 * 
	 * @return
	 */
	public List getScStyle(int styletype) {
		return this.getDictDAO().findByTypeAndRoot(14, styletype);
	}

	/**
	 * 餐厅人均
	 * 
	 * @return
	 */
	public List getCTCost() {
		return this.getDictDAO().findByType(5);
	}

	/**
	 * 商城人均
	 * 
	 * @return
	 */
	public List getScCost() {
		return this.getDictDAO().findByType(11);
	}

	/**
	 * 娱乐消费目的
	 * 
	 * @return
	 */
	public List getYlPurpose() {
		return this.getDictDAO().findByType(6);
	}

	/**
	 * 娱乐人均
	 * 
	 * @return
	 */
	public List getYlCost() {
		return this.getDictDAO().findByType(7);
	}

	/**
	 * 酒店消费目的
	 * 
	 * @return
	 */
	public List getJdPurpose() {
		return this.getDictDAO().findByType(8);
	}

	/**
	 * 酒店人均
	 * 
	 * @return
	 */
	public List getJdCost() {
		return this.getDictDAO().findByType(7);
	}

	/**
	 * 运动人均
	 * 
	 * @return
	 */
	public List getYdCost() {
		return this.getDictDAO().findByType(13);
	}

	/**
	 * 运动消费目的
	 * 
	 * @return
	 */
	public List getYdPurpose() {
		return this.getDictDAO().findByType(12);
	}

	/**
	 * 商城消费目的
	 * 
	 * @return
	 */
	public List getScPurpose() {
		return this.getDictDAO().findByType(10);
	}

	/**
	 * 商品消费目的
	 * 
	 * @return
	 */
	public List getSPPurpose() {
		return this.getDictDAO().findByType(4);
	}

	/**
	 * 商品类型
	 * 
	 * @return
	 */
	public List getSPStyletype() {
		return this.getDictDAO().findByTypeAndRoot(14, 0);
	}

	/**
	 * 商品风格
	 * 
	 * @return
	 */
	public List getSPStyle(int styletype) {
		return this.getDictDAO().findByTypeAndRoot(14, styletype);
	}

	/**
	 * 商品人均
	 * 
	 * @return
	 */
	public List getSPCost() {
		return this.getDictDAO().findByType(11);
	}

	/**
	 * 送货对象
	 * 
	 * @return
	 */
	public List getSendto() {
		return this.getDictDAO().findByType(15);
	}

	public DdSystemuserDAO getDdSystemuserDAO() {
		return ddSystemuserDAO;
	}

	public void setDdSystemuserDAO(DdSystemuserDAO ddSystemuserDAO) {
		this.ddSystemuserDAO = ddSystemuserDAO;
	}

}
